<template>
  <!-- discoveryTime (string, optional): 发现时间 ,
estateId (string, optional): 房产或地产id ,
estimatedProcessingTime (string, optional): 预计处理时间 ,
faultId (string, optional): 问题类别 ,
handlerUserId (string, optional): 处理人id ,
issueImages (string, optional): 图片信息 ,
issuesStatus (integer, optional): 0-待上传 1-未审核 2-已通过 3-未通过 ,
issueTags (string, optional),
issuesDesc (string, optional): 问题描述 ,
issuesType (integer, optional): 1-质量问题 2-安全问题 ,
partId (string, optional): 问题部分 ,
projectName (string, optional): 项目名称 ,
qualityId (string, optional): 质量问题id -->
  <div class="list-container">
    <vab-query-form>
      <el-form
        ref="form"
        :model="queryForm.queryBean"
        :inline="true"
        @submit.native.prevent
      >
        <el-form-item>
          <el-select
            v-model.trim="queryForm.queryBean.rootPartId"
            collapse-tags
            :style="{ width: '100%' }"
            placeholder="请选择类别"
            clearable
          >
            <el-option
              v-for="item in estateOptions"
              :key="item.partId"
              :label="item.partName"
              :value="item.partId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model.trim="queryForm.queryBean.handlerUserId"
            placeholder="处理人"
          />
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryForm.queryBean.issuesType"
            placeholder="类别筛选"
          >
            <el-option label="质量问题" value="1"></el-option>
            <el-option label="安全问题" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="queryForm.queryBean.statusList"
            multiple
            collapse-tags
            :style="{ width: '100%' }"
            placeholder="请选择审核状态"
            clearable
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            native-type="submit"
            @click="handleQuery"
          >
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </vab-query-form>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      style="width: 100%"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
    >
      <el-table-column
        show-overflow-tooltip
        prop="faultName"
        label="问题名称"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="地产名称"
        prop="propertyName"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="项目名称"
        prop="projectName"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="问题描述"
        prop="issuesDesc"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="状态"
        prop="issuesStatus"
        width="120"
      >
        <template #default="{ row }">
          <el-tag
            size="small"
            :type="
              row.issuesStatus == 3
                ? 'success'
                : row.issuesStatus == 4
                ? 'danger'
                : row.issuesStatus == 2
                ? 'warning'
                : 'info'
            "
          >
            {{ getValue(row.issuesStatus) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="发现时间"
        prop="discoveryTime"
        width="160"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="预计处理时间"
        prop="estimatedProcessingTime"
        width="160"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="处理人"
        prop="handlerUserId"
        width="100"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="审核" width="200">
        <template #default="{ row }">
          <el-button type="primary" @click="handleEdit(row)">详情</el-button>
          <!-- <el-button
            v-if="row.issuesStatus == 2 || row.issuesStatus == 11"
            type="primary"
            size="mini"
            @click="handlePass(row)"
          >
            通 过
          </el-button>
          <el-button
            v-if="row.issuesStatus == 2 || row.issuesStatus == 11"
            type="danger"
            size="mini"
            @click="handleRefuse(row)"
          >
            不通过
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
    <check-question ref="check" @fetch-data="fetchData"></check-question>
  </div>
</template>
<script>
  import {
    getProgressList,
    getConstantId,
    getQualityPage,
    modQualityIssue,
  } from '@/api/checked'
  import _ from 'lodash'
  import CheckQuestion from './components/CheckQuestion.vue'
  export default {
    name: 'Progress',
    components: { CheckQuestion },
    data() {
      return {
        estateOptions: [],
        options: [
          {
            value: 1,
            label: '待上传',
          },
          {
            value: 11,
            label: '已上传',
          },
          {
            value: 2,
            label: '待审核',
          },
          {
            value: 3,
            label: '已通过',
          },
          {
            value: 4,
            label: '未通过',
          },
        ],
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        selectRows: '',
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          queryBean: {
            issuesType: '质量问题',
            statusList: [4, 2, 3, 11],
          },
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.init()
      this.fetchData()
    },
    mounted() {},
    methods: {
      async init() {
        const { data } = await getConstantId()
        if (data.status == 0) {
          this.estateOptions = data.body
        } else {
        }
      },
      getValue(value) {
        switch (value) {
          case 1:
            return '待上传'
          case 11:
            return '已上传'
          case 2:
            return '待审核'
          case 3:
            return '已通过'
          case 4:
            return '未通过'
        }
      },
      handleEdit(row) {
        if (row) {
          this.$refs['check'].showEdit(row)
        } else {
          this.$refs['check'].showEdit()
        }
      },
      async handlePass(row) {
        let temp = {
          qualityId: row.qualityId,
          issuesStatus: 3,
        }
        const { data } = await modQualityIssue(temp)
        this.fetchData()
      },
      async handleRefuse(row) {
        let temp = {
          qualityId: row.qualityId,
          issuesStatus: 4,
        }
        const { data } = await modQualityIssue(temp)
        this.fetchData()
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        let temp = _.cloneDeep(this.queryForm)
        if (this.queryForm.queryBean.issuesType == '质量问题') {
          temp.queryBean.issuesType = 1
        } else {
          temp.queryBean.issuesType = Number(
            this.queryForm.queryBean.issuesType
          )
        }
        this.listLoading = true
        const { data } = await getQualityPage(temp)
        const { body } = data
        console.log(body.data)
        this.list = body.data
        // data.forEach((item, index) => {})
        this.total = body.totalSize
        this.$baseNotify('进度数据获取完毕！', '成功', 'success', 'top-right')
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
    },
  }
</script>
